package com.swsc.ai;

import com.swsc.ai.taskfactory.Task;
import com.swsc.ai.taskfactory.TaskFactory;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;

/**
 * @author QF
 * @date 2023/10/10 15:11
 * @describe
 */
public class TaskStart {

    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();

        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("-")) {
                String key = arg.substring(1);
                String value = args[++i];
                map.put(key, value);
            }
        }
        System.out.println(map);
        //计算逻辑
        TaskFactory taskFactory = new TaskFactory();
        Task task = taskFactory.getTask(map.get("className"));
        try {
            task.run(map);
        } catch (SQLException e) {
            System.out.println("获取分区异常");
        } catch (NullPointerException e) {
            throw new RuntimeException("工厂创建任务对象异常:" + Arrays.toString(e.getStackTrace()));
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }

    }
}
